<?php
class Data_popupController extends Controller{
	function actionPengajar(){
		$data = array();
		$listData = MKaryawan::model()->findAll("bagian = 'guru' and department_id =:deptId and is_active = 1",array(":deptId"=>Yii::app()->request->getParam("department_id","")));
		$data["defColumn"] = array(
				"{name: 'id', index: 'id',label:'ID', width: 20,hidden:false,sorttype:'int',formatter:'int'}",
				"{name: 'name', index: 'name',label:'Nama Pengajar', width: 40,search:true}",
				"{name: 'bagian', index: 'bagian',label:'Bagian', width: 40,search:true}",
			);
		$normalizeListData = array();
		foreach ($listData as $row){
			$normalizeListData[] = array("id"=>$row["id"],"name"=>$row["name"],"bagian"=>$row["bagian"]);
		}
		$data["jsonListData"] = CJSON::encode($normalizeListData);
		$data["callback"] = Yii::app()->request->getParam("callback","");		
		$data["title"] = Yii::t("label", "Daftar Pegawai");
		$data["searchBy"] = '["name"]';
		$this->layout = "//layouts/ly_popup";		
		$this->render("default",$data);		
	}
	
	function actionKelasTahunAjaran(){
		$data = array();
		$criteria = new CDbCriteria();
		$condition = array();
		$params = array();
		
		$criteria->addColumnCondition(array("is_active" => 1));
		$tahunAjaranId = Yii::app()->request->getParam("tahun_ajaran_id","");
		if ($tahunAjaranId != ""){
			$criteria->addColumnCondition(array("tahun_ajaran_id" => $tahunAjaranId));
			//$condition[] = "tahun_ajaran_id = :tahunAjaranId";
			$params[":tahunAjaranId"] = $tahunAjaranId;
		}
		
		$tingkatanId = Yii::app()->request->getParam("tingkatan_id","");
		if ($tingkatanId != ""){
			$criteria->addColumnCondition(array("tingkatan_id" => $tingkatanId));
			$params[":tingkatanId"] = $tingkatanId;
		}
		
		$listData = VKelasTahunAjaran::model()->findAll($criteria);
		
		$data["defColumn"] = array(
				"{name: 'id', index: 'id',label:'ID', hidden:true,sorttype:'int',formatter:'int'}",
				"{name: 'tahun_ajaran_id', index: 'tahun_ajaran_id',label:'Tahun Ajaran',hidden:true, width: 40,search:true}",
				"{name: 'tingkatan_id', index: 'tingkatan_id',hidden:true, width: 40,search:true}",
				"{name: 'tingkatan_name', index: 'tingkatan_name',label:'Tingkatan', width: 40,search:true}",
				"{name: 'kelas_name', index: 'kelas_name',label:'Kelas', width: 40,search:true}",
				"{name: 'wali_kelas_name', index: 'wali_kelas_name',label:'Wali Kelas', width: 40,search:true}",
				"{name: 'notes', index: 'notes',label:'Keterangan', width: 40,search:true}",
				"{name: 'is_active', index: 'is_active',label:'Status', width: 30, align: 'center', formatter: 'checkbox'}",
		);
		$normalizeListData = array();
		foreach ($listData as $row){
			$normalizeListData[] = array("id"=>$row["id"],
						"tahun_ajaran_id"=>$row->tahun_ajaran_id,
						"tingkatan_id"=>$row->tingkatan_id, 
						"tingkatan_name"=>$row->tingkatan_name,
						"kelas_name"=>$row->kelas_name,
						"wali_kelas_name"=>$row->wali_kelas_name,
						"notes"=>$row["notes"],
						"is_active"=>$row["is_active"],
					);
		}
		$data["jsonListData"] = CJSON::encode($normalizeListData);
		$data["callback"] = Yii::app()->request->getParam("callback","");
		$data["title"] = Yii::t("label", "Daftar Kelas");
		$data["searchBy"] = '["tingkatan_name","kelas_name","wali_kelas_name","notes"]';
		$this->layout = "//layouts/ly_popup";
		$this->render("default",$data);
	}
	
	function actionTahunAjaran(){
		/* output ke bukan default */
		$data["callback"] = Yii::app()->request->getParam("callback","");		
		$data["title"] = Yii::t("label", "Daftar Pegawai");
		$this->layout = "//layouts/ly_popup";
		$this->render("tahunAjaran",$data);
	}

	function actionStudentClass(){
		$data = array();
		$criteria = new CDbCriteria();
		$condition = array();
	
		$criteria->addColumnCondition(array("is_active" => 1));
		
		$kelasTahunAjaranId = Yii::app()->request->getParam("kelas_tahun_ajaran_id","");
		
		if ($kelasTahunAjaranId != ""){
			$criteria->addColumnCondition(array("kelas_tahun_ajaran_id" => $kelasTahunAjaranId));
		}
		$listData = MStudentClass::model()->findAll($criteria);
	
		$data["defColumn"] = array(
				"{name: 'id', index: 'id',label:'ID', hidden:true,sorttype:'int',formatter:'int'}",
				"{name: 'kelas_tahun_ajaran_id', index: 'kelas_tahun_ajaran_id',hidden:true, width: 40,search:true}",
				"{name: 'student_id', index: 'student_id',hidden:true,width: 20,search:true}",
				"{name: 'sid', index: 'sid',label:'Student ID', width: 20,search:true}",
				"{name: 'student_name', index: 'student_name',label:'Name', search:true}",
				"{name: 'student_sex', index: 'student_sex',label:'Jenis Kelamin', width: 20,search:true,
					formatter:'select',
					editoptions:{value:'L:Laki-laki;P:Perempuan'},
				}",				
		);
		
		$normalizeListData = array();
		foreach ($listData as $row){
			$normalizeListData[] = array("id"=>$row["id"],
					"kelas_tahun_ajaran_id"=>$row->kelas_tahun_ajaran_id,
					"student_id"=>$row->student->id,
					"sid"=>$row->student->sid,
					"student_name"=>$row->student->name,
					"student_sex"=>$row->student->gender,					
			);
		}
		$data["jsonListData"] = CJSON::encode($normalizeListData);
		$data["searchBy"] = '["sid","student_name"]';		
		$data["callback"] = Yii::app()->request->getParam("callback","");
		$data["title"] = Yii::t("label", "Daftar Siswa");
		$this->layout = "//layouts/ly_popup";
		$this->render("default",$data);
	}
}
?>

